module.exports = function ($scope,$stateParams, $resource, $state, $http, toaster) {
  var tcode = $stateParams.tcode
  console.log(tcode);
  /**
   * 初始化经度
   */
  $scope.longitude = 123.492522;
  /**
   * 初始化纬度
   */
  $scope.latitude= 41.812736;
/**
       * 初始化百度地图
       */
      
      $scope.initBap = function () {
        $scope.map = new BMap.Map("container"); // 创建地图实例
        $scope.map.centerAndZoom(new BMap.Point($scope.longitude, $scope.latitude), 15);  // 初始化地图，设置中心点坐标和地图级别
        $scope.map.addControl(new BMap.NavigationControl());
        $scope.map.addControl(new BMap.ScaleControl());
        $scope.map.addControl(new BMap.OverviewMapControl());
        $scope.map.enableScrollWheelZoom(true);

        var driving = new BMap.DrivingRoute($scope.map);

        // var p1 = new BMap.Point(123.485482,41.808768);
        // var p2 = new BMap.Point(123.497699,41.81358);
        
        // driving.search(p1, p2);
        driving.setSearchCompleteCallback(function(){
          var pts = driving.getResults().getPlan(0).getRoute(0).getPath();    //通过驾车实例，获得一系列点的数组
  
          var polyline = new BMap.Polyline(pts);     
          $scope.map.addOverlay(polyline);
          // $scope.addmarker(p1);
          // $scope.addmarker(p2);
        })




      $scope.addmarker = function (point,name){
          var myIcon = new BMap.Icon("http://shangke2.oss-cn-qingdao.aliyuncs.com/img/map_mark.png", new BMap.Size(21,60));
          var marker = new BMap.Marker(point,{icon:myIcon});
          $scope.map.addOverlay(marker);
          $scope.createTag(marker,name);
        }
      };

     
      $scope.createTag = function (marker,name){

        //标注
        var text =  name ; 
        //给标记添加点击事件以及显示窗口信息
         var infoWindow = new BMap.InfoWindow( text );
         marker.addEventListener("click", function () { 
           this.openInfoWindow(infoWindow);
           
         });
    }

    $resource('/api/ac/ggc/faceDiscernService/findFDspotssList', {}, {}).get({"create_by":$scope.info.bind_seller_login_code}, function (res) {
			if (res.errcode === 0) {
        $scope.binglist = res.data.reslist;
        $scope.peosum = res.data.sum;
        console.log($scope.peosum);
        if(res.data.warning =='1'){
	        toaster.error({title: '', body: "当前景区已达到预警人数！"});
        }
			} else {
				toaster.error({title: '', body: res.errmsg});
      }
      init($scope.binglist);
		});

    

      $scope.initBap();

      
      function init(data){
        $scope.piechart1 = {
          'title': '景区实时数据',
          'data': data
        }
      }
      $scope.chart1 = {
        'showData': 'a7',
        'linename': ["人数(名)"],
        'data': [100,20,23,43,453,23,22],
        'setting': {
          'tooltip': {'trigger':'axis'},
          'serietype': 'bar',
          'boundaryGap': false
        },
        xaxis:"1234567"
      }

  }